package com.zhuyuan.system.controller;

import com.zhuyuan.core.util.Result;
import com.zhuyuan.database.base.BaseController;
import com.zhuyuan.system.api.domain.SysUser;
import com.zhuyuan.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 张琳凯
 * @Description: TODO
 * @DateTime: 2025/2/9 17:37
 **/
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController extends BaseController {

    private final ISysUserService sysUserService;

    @GetMapping("/list")
    public Result<?> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                SysUser sysUser) {
        return Result.ok(sysUserService.queryUserList(pageNum, pageSize, sysUser));
    }

    @GetMapping("/getInfo")
    public Result<?> getInfo() {
        return Result.ok(sysUserService.getDetailInfo());
    }

    @GetMapping("/info")
    public Result<?> infoByUserNameOrPhone(@RequestParam("username")String username,@RequestParam("phone")String phone) {
        if (StringUtils.isNoneEmpty(username)){
            return Result.ok(sysUserService.queryByUserName(username));
        }else if (StringUtils.isNoneEmpty(phone)){
            return Result.ok(sysUserService.queryByPhone(phone));
        }
        throw new IllegalArgumentException("请检查参数");
    }
}
